/* 
  根据配置的显示样式获取对应className 
  style 表单设计器配置的样式
  type 样式的类型 5种情况 formStyle groupStyle fieldTitleStyle fieldContentStyle tableGroupTitleStyle
*/
export function diffStyle(configStyle, type) {
  if(!configStyle || !type){
    return "";
  }
  let defaultStyle = {
    formStyle:{
      fontFamily:"Microsoft Yahei",
      fontSize:"16px",
      color:"#222222",
      fontWeight:"normal",
      textAlign:"center",
      backgroundColor:"#ffffff"
    },//表单标题
    groupStyle:{
        fontFamily:"Microsoft Yahei",
        fontSize:"14px",
        color:"#222222",
        fontWeight:"normal",
        textAlign:"left",
        backgroundColor:"#F5F5F5"
    },//分组标题
    fieldTitleStyle:{
        fontFamily:"Microsoft Yahei",
        fontSize:"13px",
        color:"#666666",
        fontWeight:"normal",
        textAlign:"initial",
        backgroundColor:"transparent"
    },//字段label
    fieldContentStyle:{
        fontFamily:"Microsoft Yahei",
        fontSize:"13px",
        color:"#222222",
        fontWeight:"normal",
        textAlign:"initial",
        backgroundColor:"transparent"
    },//字段内容
    tableGroupTitleStyle:{
        fontFamily:"Microsoft Yahei",
        fontSize:"13px",
        color:"#666666",
        fontWeight:"normal",
        textAlign: "initial",
        backgroundColor:"transparent"
    }
  };

  let returnStyle = [];
  for (const styleKey in configStyle) {//遍历配置的样式
    if(defaultStyle[type].hasOwnProperty(styleKey)){//默认配置存在对应的style样式
      var styleValue = configStyle[styleKey];//配置的样式值
      if(styleValue){//configStyle[styleKey] 有可能存在脏数据null，会导致下面报错，做容错处理
        var defaultStyleValue = defaultStyle[type][styleKey];
        if(defaultStyleValue !== styleValue){
          let clsName = "config-" ;
          if(styleKey === 'backgroundColor'){//如果是背景色
            clsName += "bg-"
          }
          clsName += styleValue.replace("#", "").replace(" ", "");//如果配置的样式跟默认样式不一致，则返回一个className，加上前缀 config 把#替换掉 比如配置的背景色为 #ffffff 则返回 config-ffffff
          returnStyle.push(clsName);
        }
      }
    }
  }
  
  return returnStyle.join(" ");
}
